
producechannel producecc
efficiencychannel efficiencycc
financechannel financecc
tradechannel tradecc
warehousechannel warehousecc
logisticschannel logisticscc 
securitychannel securitycc 


stonecustomerchannel 寿山石客户信息通道 stonecustomercc
stoneidentityorgchannel 寿山石鉴定机构通道 stoneidentityorgcc
stoneidentityresultchannel 寿山石鉴定结果通道 stoneidentityresultcc
stonestoragechannel 寿山石仓储物流通道 stonestoragecc
stoneinstallationchannel 寿山石安装维护通道 stoneinstallationcc



##1.上传合约代码****.go 到
cd /home/minbao/go/src/github.com/hyperledger/minbao-network/chaincode/go
（docker：/opt/gopath/src/github.com/hyperledger/fabric-cluster/chaincode/go）

##2.进入cli容器 
docker exec -it cli bash 
cd /opt/gopath/src/github.com/hyperledger/fabric-cluster/chaincode/go

##3.对合约代码进行依赖打包   指令：
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
go mod vendor 

scp -P 10022  *.tar.gz minbao@192.168.1.190:/home/minbao/go/src/github.com/hyperledger/minbao-network/chaincode/go

scp -P 10022  *.tar.gz minbao@192.168.1.55:/home/minbao/go/src/github.com/hyperledger/minbao-network/chaincode/go


    # 打包合约
peer lifecycle chaincode package tradecc.tar.gz --path /opt/gopath/src/github.com/hyperledger/fabric-cluster/chaincode/go --lang golang --label tradecc_1 
# 打包，并复制到各个从服务器上/home/minbao/go/src/github.com/hyperledger/minbao-network/chaincode/go的路径下

##4.安装合约(Org节点都执行一次)
peer lifecycle chaincode install tradecc.tar.gz //安装
    ##执行安装后会返回包ID，注意包ID是一个键值对（同一个gz包会返回同一个ID）
    warehousecc_1:b9277cf1d8dfbd698307b6145884a7911364dee042113c27281e3ecdc48cd7bc
    producecc_1:6eede0f15827cbccfa890b435a26027d6c27b018d4a6bc9893dd68660f836258
    logisticscc_1:5ca52e7785ae15a5e8b60c85d34fb0d39093101a60e3b5a70f380a9b6bc53f1b
##5.查询通道的commit序列号[Sequence] 如果Sequence为1 那么后续步骤的涉及Sequence的需要改为2（每次安装+1）	
peer lifecycle chaincode querycommitted -C tradechannel --name tradecc //查看通道的commit 序列号

##6.Org节点同意此次安装申请 留意channelID --name --package-id --sequence 这几个参数按照实际填写
peer lifecycle chaincode approveformyorg --channelID tradechannel --name tradecc --version 1.0 --init-required --package-id tradecc_1:96e05aa2b2d3e85930f99146e7f4a7707332ae209323fb5b54d11c6708556e50 --sequence 3 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/fjminbao.cn/orderers/orderer0.fjminbao.cn/msp/tlscacerts/tlsca.fjminbao.cn-cert.pem 
//同意提交（Org1-179和Org2-194轮流执行）

##7.检查commit状态是否2个Org都同意了，也就这条指令的结果"approvals"是2个true
peer lifecycle chaincode checkcommitreadiness --channelID tradechannel --name tradecc --version 1.0 --init-required --sequence 3 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/fjminbao.cn/orderers/orderer0.fjminbao.cn/msp/tlscacerts/tlsca.fjminbao.cn-cert.pem --output json //检查commit状态


//重复以上安装-同意提交步骤 最后执行以下操作
peer lifecycle chaincode commit -o orderer0.fjminbao.cn:7050 --channelID tradechannel --name tradecc --version 1.0 --sequence 3 --init-required --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/fjminbao.cn/orderers/orderer0.fjminbao.cn/msp/tlscacerts/tlsca.fjminbao.cn-cert.pem --peerAddresses peer0.org1.fjminbao.cn:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.fjminbao.cn/peers/peer0.org1.fjminbao.cn/tls/ca.crt --peerAddresses peer0.org2.fjminbao.cn:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.fjminbao.cn/peers/peer0.org2.fjminbao.cn/tls/ca.crt //提交commit


调用链码初始化方法：
peer chaincode invoke -o orderer0.fjminbao.cn:7050 --isInit --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/fjminbao.cn/orderers/orderer0.fjminbao.cn/msp/tlscacerts/tlsca.fjminbao.cn-cert.pem -C tradechannel -n tradecc --peerAddresses peer0.org1.fjminbao.cn:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.fjminbao.cn/peers/peer0.org1.fjminbao.cn/tls/ca.crt --peerAddresses peer0.org2.fjminbao.cn:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.fjminbao.cn/peers/peer0.org2.fjminbao.cn/tls/ca.crt -c '{"Args":["init",""]}'    --waitForEvent




------------------------------------------------------------------------------


scp efficiencycc.tar.gz minbao@192.168.1.55:/home/minbao/go/src/github.com/hyperledger/minbao-network/

docker cp efficiencycc.tar.gz cli:/opt/gopath/src/github.com/hyperledger/fabric/peer


------------------------------------------------------------------------------

peer chaincode query -C efficiencychannel -n efficiencycc -c '{"Args":["query","1001","1002","2021-01-01","2021-01-31"]}'
peer chaincode query -C efficiencychannel -n efficiencycc -c '{"Args":["query","1001","2020-01-31"]}'


peer chaincode query -C efficiencychannel -n efficiencycc -c '{"Args":["query","{\"selector\": { \"employeeId\":\"1001\"}}"]}'


{"selector":{"$and":[{"employeeId": "1001"},{"productionDate": {"$gte": "2020-01-01","$lte": "2020-12-31"}}]}}



peer chaincode query -C producechannel -n producecc -c '{"Args":["query","G0005","2020-11-23 10:05:27","2020-11-24 10:05:27"]}'

peer chaincode query -C securitychannel -n securitycc -c '{"Args":["query","SC0001","2020-11-23","2020-11-24"]}'
peer chaincode query -C securitychannel -n securitycc -c '{"Args":["query","SC0001","2020-11-23 11:55:00"]}'
peer chaincode query -C tradechannel -n tradecc -c '{"Args":["query","{"limit": 1000,"selector": {},"skip": 0}"]}'
peer chaincode query -C tradechannel -n tradecc -c '{"Args":["queryByRange","","2020-11-23 00:00:00","2021-11-27 09:45:38"]}'


peer chaincode query -C financechannel -n financecc -c '{"Args":["query","G0003","2020-11-27 00:05:27","2020-11-27 24:05:27"}'



{"selector":{"_id":{"$regex":"Transaction"},"transactionTime":{"$gte":"2020-11-01 00:00:00","$lte":"2020-11-30 23:59:59"}}}

{"selector":{"_id":{"$regex":"Transaction"},"transactionTime":{"$gte":"2020-11-23 00:00:00","$lte":"2020-11-27 09:45:38"}}}


peer chaincode query -C efficiencychannel -n efficiencycc -c '{"Args":["query","{\"selector\": { \"employeeId\":\"1001\"}}"]}'

peer chaincode query -C warehousechannel -n warehousecc -c '{"Args":["queryBySelectors","{\"selector\":{\"_id\":{\"$gt\": null}}}"]}'

peer chaincode query -C logisticschannel -n logisticscc -c '{"Args":["query","1001","CN202101260000"]}'


gRPC failure=Status{code=UNAVAILABLE, description=Channel shutdownNow invoked, cause=null}

peer chaincode invoke -C producechannel -n producecc -c 
{
    "deptId":"1005",
    "accidentCause": "",
    "accidentHandling": "",
    "createTime": "2021-01-18 10:00:07",
    "factoryId": "G0003",
    "factoryName": "加解密测试123123",
    "inputAmount": "1000",
    "inventory": "171000",
    "orderId": "8200",
    "outputAmount": "200",
    "quality": "不合格",
    "validityDate": "16"
}


peer chaincode invoke -C efficiencychannel -n efficiencycc -o 172.21.0.3:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.fjminbao.cn/peers/peer1.org1.fjminbao.cn/tls/server.crt -c '{"Args":["create","1","10","1111","1111","1","99999","2021-01-21 17:00:00,"6666"]}'

{"absenteeism":"1","defectiveQuantity":"10","deptId":"1001","employeeId":"1001","humanError":"1","laborCost":"17000","productionDate":"2021-01-21 17:19:03","realProduction":"2365"}

HR
peer chaincode invoke -o orderer0.fjminbao.cn:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/fjminbao.cn/orderers/orderer0.fjminbao.cn/msp/tlscacerts/tlsca.fjminbao.cn-cert.pem -C efficiencychannel -n efficiencycc --peerAddresses peer0.org1.fjminbao.cn:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.fjminbao.cn/peers/peer0.org1.fjminbao.cn/tls/ca.crt --peerAddresses peer0.org2.fjminbao.cn:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.fjminbao.cn/peers/peer0.org2.fjminbao.cn/tls/ca.crt -c '{"Args":["create","1","10","1111","1111","1","99999","2021-01-21 17:00:00","6666"]}' --waitForEvent

生产
peer chaincode invoke -o orderer0.fjminbao.cn:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/fjminbao.cn/orderers/orderer0.fjminbao.cn/msp/tlscacerts/tlsca.fjminbao.cn-cert.pem -C producechannel -n producecc --peerAddresses peer0.org1.fjminbao.cn:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.fjminbao.cn/peers/peer0.org1.fjminbao.cn/tls/ca.crt --peerAddresses peer0.org2.fjminbao.cn:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.fjminbao.cn/peers/peer0.org2.fjminbao.cn/tls/ca.crt -c '{"Args":["create","","","2021-01-22 09:16:59","1001","G0003","广东地球土壤研究院","1000","12000"，"8900","100001","1000","95","优质","16"]}' --waitForEvent

财务
peer chaincode invoke -o orderer0.fjminbao.cn:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/fjminbao.cn/orderers/orderer0.fjminbao.cn/msp/tlscacerts/tlsca.fjminbao.cn-cert.pem -C financechannel -n financecc --peerAddresses peer0.org1.fjminbao.cn:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.fjminbao.cn/peers/peer0.org1.fjminbao.cn/tls/ca.crt --peerAddresses peer0.org2.fjminbao.cn:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.fjminbao.cn/peers/peer0.org2.fjminbao.cn/tls/ca.crt -c '{"Args":["create","1001","广东地球土壤研究院","2021-01-25 09:16:59","9898989898","10101104","555555","33333","222222"，"10101011","5464321","666666","950000","952222","456789213","78465312","451325645","123545","456231546","551235123","451234512345","451235225","45321543125","456123465","230923879"]}' --waitForEvent

peer chaincode invoke -o orderer0.fjminbao.cn:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/fjminbao.cn/orderers/orderer0.fjminbao.cn/msp/tlscacerts/tlsca.fjminbao.cn-cert.pem -C efficiencychannel -n efficiencycc --peerAddresses peer0.org1.fjminbao.cn:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.fjminbao.cn/peers/peer0.org1.fjminbao.cn/tls/ca.crt --peerAddresses peer0.org2.fjminbao.cn:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.fjminbao.cn/peers/peer0.org2.fjminbao.cn/tls/ca.crt -c '{"Args":["create","1001","广东地球土壤研究院","2021-01-25 09:16:59","9898989898","10101104","555555","33333","222222"，"10101011","5464321","666666","950000","952222","456789213","78465312","451325645","123545","456231546","551235123","451234512345","451235225","45321543125","456123465","230923879"]}' --waitForEvent



time 
peer chaincode invoke -o orderer0.fjminbao.cn:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/fjminbao.cn/orderers/orderer0.fjminbao.cn/msp/tlscacerts/tlsca.fjminbao.cn-cert.pem -C tradechannel -n tradecc --peerAddresses peer0.org1.fjminbao.cn:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.fjminbao.cn/peers/peer0.org1.fjminbao.cn/tls/ca.crt --peerAddresses peer0.org2.fjminbao.cn:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.fjminbao.cn/peers/peer0.org2.fjminbao.cn/tls/ca.crt -c '{"Args":["queryByKey", "2021-01-29 08:00:00","202101T000000081"]}' --waitForEvent




peer chaincode invoke -o orderer0.fjminbao.cn:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/fjminbao.cn/orderers/orderer0.fjminbao.cn/msp/tlscacerts/tlsca.fjminbao.cn-cert.pem -C logisticschannel -n logisticscc --peerAddresses peer0.org1.fjminbao.cn:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.fjminbao.cn/peers/peer0.org1.fjminbao.cn/tls/ca.crt --peerAddresses peer0.org2.fjminbao.cn:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.fjminbao.cn/peers/peer0.org2.fjminbao.cn/tls/ca.crt -c '{"Args":["query", "{selector: {deliveryOrderNum: 1615946098}}"]}' --waitForEvent



peer chaincode invoke -o orderer2.fjminbao.cn:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/fjminbao.cn/orderers/orderer2.fjminbao.cn/msp/tlscacerts/tlsca.fjminbao.cn-cert.pem -C logisticschannel -n logisticscc --peerAddresses peer0.org1.fjminbao.cn:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.fjminbao.cn/peers/peer0.org1.fjminbao.cn/tls/ca.crt --peerAddresses peer0.org2.fjminbao.cn:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.fjminbao.cn/peers/peer0.org2.fjminbao.cn/tls/ca.crt -c '{"Args":["query", "202101T000000081","2021-01-29 08:00:00","2021-01-29 18:00:00"]}' --waitForEvent


peer chaincode instantiate -o orderer2.fjminbao.cn:7050 -n tradecc -v 1.0 -C tradechannel --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/fjminbao.cn/orderers/orderer0.fjminbao.cn/msp/tlscacerts/tlsca.fjminbao.cn-cert.pem 

peer chaincode instantiate -o orderer0.fjminbao.cn:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/fjminbao.cn/orderers/orderer0.fjminbao.cn/msp/tlscacerts/tlsca.fjminbao.cn-cert.pem -C tradechannel -n tradecc -l golang -v 1.0 -c '{"Args":["init",""]}' 

peer chaincode invoke -o orderer0.fjminbao.cn:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/fjminbao.cn/orderers/orderer0.fjminbao.cn/msp/tlscacerts/tlsca.fjminbao.cn-cert.pem --peerAddresses peer0.org2.fjminbao.cn:7051 -C tradechannel -n tradecc -I -c '{"Args":["Init", "a","1000","b", "1000"]}'